{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox-title">
        <h5>用户协议</h5>
    </div>
    <div class="ibox-content layui-form">
        <div class="layui-row layui-col-space10 layui-form-item ">
            <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                <label class="layui-form-label">用户协议：</label>
                <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                    <p>{$agreement}</p>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    layui.use(['form'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            data.field.agreement = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('userAgreement')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Other/userAgreement')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>
</body>
</html>